import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import './assets/global.less'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// // 导入富文本编辑器的样式
// import 'quill/dist/quill.core.css'
// import 'quill/dist/quill.snow.css'
// import 'quill/dist/quill.bubble.css'

// 全局注册富文本编辑器
Vue.use(VueQuillEditor)
axios.defaults.baseURL = 'http://www.liulongbin.top:3008'
Vue.config.productionTip = false
Vue.prototype.$http = axios
// 请求拦截 添加请求头
axios.interceptors.request.use(config => {
  // console.log(config.url.startsWith('/my'))
  if (config.url.startsWith('/my')) {
    config.headers.Authorization = store.state.user.token
  }
  return config
}, error => {
  return Promise.reject(error)
})
// 响应拦截器
axios.interceptors.response.use(response => {
  return response
}, error => {
  if (error.response.status === 401) {
    Vue.prototype.$message.error(error.response.data.message)
    router.push('/login')
    store.commit('user/updateToken', '')
    store.commit('user/updateUserInfo', {})
  }
  return Promise.reject(error)
})

Vue.use(ElementUI)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
